﻿#region File Description
//-----------------------------------------------------------------------------
// ActionTask
//
// Copyright © 2013 Wave Coorporation. All rights reserved.
// Use is subject to license terms.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Diagnostics;
using WaveEngine.Framework;
#endregion

namespace WaveEngine.Extensions.ITasks
{
    public class ActionTask : TaskBase
    {
        private Action action;

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionTask" /> class.
        /// </summary>
        /// <param name="scene">The scene.</param>
        /// <param name="taskName">Name of the task.</param>
        /// <param name="action">The action.</param>
        internal ActionTask(Scene scene, string taskName, Action action)
            : base(scene, taskName)
        {
            this.action = action;
        }

        internal ActionTask(ITask parent, string taskName, Action action)
            : base(parent, taskName)
        {
            this.action = action;
        }

        /// <summary>
        /// Ons the run.
        /// </summary>
        [DebuggerStepThrough]
        protected override void performRun()
        {
            this.action();
            this.performCompleted();
        }

        public override IEnumerable<ITask> ChildTasks
        {
            get { return System.Linq.Enumerable.Empty<ITask>(); }
        }
    }
}
